# -*- coding: utf-8 -*-
inputstr=raw_input()
#pis=[]
#ais=[]
#tis=[]
#for i in range(len(inputstr)):
#    if inputstr[i] == 'P':
#        pis.append(i)
#    if inputstr[i] == 'A':
#        ais.append(i)
#    if inputstr[i] == 'T':
#        tis.append(i)
#
#count = 0
#for pi in pis:
#    for ai in ais:
#        if pi<ai:
#            for ti in tis:
#                if ai<ti:
#                    count+=1
#                    count%=1000000007
#
#print count

count = 0
pi=0

tcount = [0]*(len(inputstr)+1)
for i in range(len(inputstr)-1, -1, -1):
    
    if inputstr[i] == 'T':
        tcount[i]=tcount[i+1]+1
    else:
        tcount[i]=tcount[i+1]

for i in range(len(inputstr)):
    if inputstr[i] == 'P':
        pi+=1
    if inputstr[i] == 'A':
        count+=pi*tcount[i]#inputstr[i:].count('T')
        count%=1000000007

print count